package com.game.db;

import com.dats.db.NameKeyUnit;
import com.dats.db.NameMap;
import com.game.bean.AccountRole;
import com.game.bean.Role;

import java.util.HashMap;
import java.util.Map;

/**
 * @author sig
 * @since 2016/9/25
 */
public enum NameKey {
    role(Role.class, new NameKeyUnit("role", "id", "")),
    accountRole(AccountRole.class, new NameKeyUnit("accountRole", "id", "roleId")),
    ;

    private Class<?> clazz;
    private NameKeyUnit nameKeyUnit;
    private static Map<Class<?>, NameKeyUnit> classMap = new HashMap<>();

    static {
        for (NameKey tmp : NameKey.values())
            classMap.put(tmp.getClazz(), tmp.getNameKeyUnit());
    }

    NameKey(Class<?> clazz, NameKeyUnit nameKeyUnit) {
        this.clazz = clazz;
        this.nameKeyUnit = nameKeyUnit;
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public NameKeyUnit getNameKeyUnit() {
        return nameKeyUnit;
    }

    public static Map<Class<?>, NameKeyUnit> getClassMap() {
        return classMap;
    }

    public static void put(Class<?> clazz) {
        NameKeyUnit unit = classMap.get(clazz);

        if (null != unit) NameMap.put(clazz, unit);
    }

    public static void putAll() {
        for (Class<?> tmp : classMap.keySet()) {

            if (null != tmp) put(tmp);
        }
    }
}
